var pId = null;//科室
var dId = null;//医生



$(function(){
	//科室
	$.ajax({
		type:"GET",
		//data:"",
		url:"pshow.do",
		dataType:"json",
		success:function(data){
			var pid = $("#pid").val();
			//alert(pid);
			var op = "<option value=\"0\">--请选择--</option>";
			for(var i=0;i<data.key.length;i++){
				if(pid!=null && pid!=undefined && data.key[i].pId==pid){
					op +="<option value=\""+data.key[i].pId+"\" selected=\"selected\">"+data.key[i].pName+"</option>";
				}else{
					op +="<option value=\""+data.key[i].pId+"\">"+data.key[i].pName+"</option>";	
				}
			}
			$("#pId").html(op);
		}
	});
	
	//医生(根据科室id查询下面有的所有医生)
	$("#pId").change(function(){
		//alert($(this).val());
		$("#dId option:gt(0)").remove();
		$.ajax({
			type:"post",
			dataType:"json",
			url:"dpshow.do",
			data:{"proid":$(this).val()},
			success:function(data){
				//var did = $("#did").val();
				var od = "";
				for(var j=0;j<data.key.length;j++){
					od += "<option value=\""+data.key[j].dId+"\">"+data.key[j].dName+"</option>";
				}
				$("#dId").html(od);
			}
			
		});
	});
	
});